<?php

use Faker\Factory as Faker;
use App\Models\ChannelManager;
use App\Repositories\ChannelManagerRepository;

trait MakeChannelManagerTrait
{
    /**
     * Create fake instance of ChannelManager and save it in database
     *
     * @param array $channelManagerFields
     * @return ChannelManager
     */
    public function makeChannelManager($channelManagerFields = [])
    {
        /** @var ChannelManagerRepository $channelManagerRepo */
        $channelManagerRepo = App::make(ChannelManagerRepository::class);
        $theme = $this->fakeChannelManagerData($channelManagerFields);
        return $channelManagerRepo->create($theme);
    }

    /**
     * Get fake instance of ChannelManager
     *
     * @param array $channelManagerFields
     * @return ChannelManager
     */
    public function fakeChannelManager($channelManagerFields = [])
    {
        return new ChannelManager($this->fakeChannelManagerData($channelManagerFields));
    }

    /**
     * Get fake data of ChannelManager
     *
     * @param array $postFields
     * @return array
     */
    public function fakeChannelManagerData($channelManagerFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'channel_id' => $fake->randomDigitNotNull,
            'wechat_user_id' => $fake->randomDigitNotNull,
            'status' => $fake->randomDigitNotNull,
            'updated_at' => $fake->word,
            'created_at' => $fake->word
        ], $channelManagerFields);
    }
}
